package com.squid.search.service.index;

import co.elastic.clients.elasticsearch._types.mapping.Property;
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
import co.elastic.clients.elasticsearch.indices.GetIndexResponse;
import co.elastic.clients.elasticsearch.indices.IndexSettings;
import co.elastic.clients.util.ObjectBuilder;

import java.util.HashMap;
import java.util.function.Function;

/**
 * Description
 *
 * @author jinhang
 * @since 2024-2-8
 **/
public interface EsIndexService {
    /**
     * Description 新建索引，指定索引名称
     *
     * @param name
     * @author jinhang1
     * @since 2024/02/23
     */
    void createIndex(String name);

    /**
     * Description 创建索引，指定索引名称和setting和mapping
     *
     * @param name      - 索引名称
     * @param settingFn - 索引参数
     * @param mappingFn - 索引结构
     * @author jinhang1
     * @since 2024/02/23
     */
    void createIndex(String name, Function<IndexSettings.Builder, ObjectBuilder<IndexSettings>> settingFn,
                     Function<TypeMapping.Builder, ObjectBuilder<TypeMapping>> mappingFn);

    /**
     * Description 删除索引
     *
     * @param name
     * @author jinhang1
     * @since 2024/02/23
     */
    void deleteIndex(String name);

    /**
     * Description
     * 修改索引字段信息
     * 字段可以新增，已有的字段只能修改字段的 search_analyzer 属性。
     *
     * @param name        - 索引名称
     * @param propertyMap - 索引字段，每个字段都有自己的property
     * @author jinhang1
     * @since 2024/02/23
     */
    void updateIndexProperty(String name, HashMap<String, Property> propertyMap);

    /**
     * Description 查询索引列表
     *
     * @return {@link GetIndexResponse }
     * @author jinhang1
     * @since 2024/02/23
     */
    GetIndexResponse getIndexList();

    /**
     * Description 查询索引详情
     *
     * @param name
     * @return {@link GetIndexResponse }
     * @author jinhang1
     * @since 2024/02/23
     */
    GetIndexResponse getIndexDetail(String name);

    /**
     * Description 检查指定名称的索引是否存在
     *
     * @param name
     * @return boolean
     * @author jinhang1
     * @since 2024/02/23
     */
    Boolean indexExists(String name);
}
